import { defineStore } from 'pinia'
import { KEEP_ALIVE_STORE_NAME } from '../const'

export default defineStore(KEEP_ALIVE_STORE_NAME, () => {
  const keepAliveList = ref([])
  const isShowRoute = ref(true)

  function addKeepAlive(component) {
    !keepAliveList.value.includes(component) &&
      keepAliveList.value.push(component)
  }

  function setKeepAlive(components) {
    console.log(components)
    keepAliveList.value = components
  }

  function removeKeepAlive(component) {
    keepAliveList.value = keepAliveList.value.filter(
      (item) => item !== component,
    )
  }

  function clearKeepAlive() {
    keepAliveList.value = []
  }

  function setRouteShow(value) {
    isShowRoute.value = value
  }

  return {
    keepAliveList,
    isShowRoute,
    addKeepAlive,
    setKeepAlive,
    removeKeepAlive,
    clearKeepAlive,
    setRouteShow,
  }
})
